<template>
  <div class="breadcrumb-wrapper">
    <div class="title">当前位置：</div>
    <!--<el-breadcrumb  separator="/">-->
      <!--<el-breadcrumb-item>{{fileTypeMap[fileType]}}</el-breadcrumb-item>-->
    <!--</el-breadcrumb>-->
    <el-breadcrumb  separator="/">
      <!--<el-breadcrumb-item-->
              <!--v-for="(item, index) in itemNavi"-->
              <!--@click.native="naviItemsClick(index)"-->
      <!--&gt;{{item}}</el-breadcrumb-item>-->

      <el-breadcrumb-item
              v-for="(item, index) in breadCrumbList"
              :key="index"
              @click.native="bcRefresh(item.path)"
              :to="{ query: { filePath: item.path, fileType: 0 } }"
      >{{item.name}}</el-breadcrumb-item>
    </el-breadcrumb>


  </div>
</template>

<script>
    import Bus from "@/common/evenBus"
export default {
  name: 'BreadCrumb',
    created(){
       // this.$router.push({path: '/netdisk/person', query: {filePath: '/a'}})
        // this.$router.push({path:’/test’,query:{page:page,pageSize:pageSize}})
        //this.$route.query.filePath='/'
      // Bus.$on("curPath",(message)=>{
      //       this.itemNavi.push(message);
      //   });
    },
  data() {
    return {
        itemNavi:['全部文件','java学习资料'],
      fileTypeMap: {
        1: '全部图片',
        2: '全部文档',
        3: '全部视频',
        4: '全部音乐',
        5: '其他',
        6: '回收站'
      }
    }
  },


    computed: {
        //  面包屑导航栏数组
        breadCrumbList: {
            get() {

                let filePath = this.$route.query.filePath
                let filePathList = filePath!=null ? filePath.split('/') : []
                let res = [] //  返回结果数组
                let _path = [] //  存放祖先路径
                if (filePathList.length==0){
                    res.push({
                        path: '/',
                        name: '全部文件'
                    })
                } else {
                for (let i = 0; i < filePathList.length; i++) {
                    if (filePathList[i]) {
                        _path.push(filePathList[i] + '/')
                        res.push({
                            path: _path.join(''),
                            name: filePathList[i]
                        })
                    } else if (i === 0) {
                        //  根目录
                        filePathList[i] = '/'
                        _path.push(filePathList[i])
                        res.push({
                            path: '/',
                            name: '全部文件'
                        })
                    }
                }}
                return res
            },
            set() {
                return []
            }
        },

    },
    methods: {
        bcRefresh(data){
            Bus.$emit("refresh",data)
        },
        naviItemsClick(data) {

            this.itemNavi.splice(data + 1, this.itemNavi.length - data);
            //alert(this.itemNavi.length)
        }
    },
}
</script>

<style lang="stylus" scoped>
.breadcrumb-wrapper
  padding 0
  height 30px
  line-height 30px
  display flex
  .title, >>> .el-breadcrumb
    height 30px
    line-height 30px
</style>